﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using KPIS.GERP.Models;
using System.Linq.Expressions;
using KPIS.GERP.Models.Class;

namespace KPIS.GERP.WCF.ESS
{
	[ServiceContract]
	public interface ITableService
	{
		[OperationContract]
		IEnumerable<T> Find<T>(Expression<Func<T, bool>> predicate) where T : class;
	}

	[ServiceErrorBehavior(typeof(ElmahErrorHandler))]
	public class TableService : ITableService
	{
		public IEnumerable<T> Find<T>(Expression<Func<T, bool>> predicate) where T : class
		{
			using (var context = new GERPContext())
			{
				var stuff = context.Set<T>().Where(predicate).ToList<T>();
				return stuff;    
			}
		}
	}
}